<template>
	<view class="fuyao-body tn-padding-sm">
		<!-- <view class="view1 tn-margin-bottom-sm">
			<view class="avatar-item tn-float-left">
				<tn-avatar src="https://img1.baidu.com/it/u=946811137,302769443&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1669309200&t=f41038b274ad95001481ff67599c99e2"></tn-avatar>
			</view>
			<view class="tn-float-left names-view">
				李小宝的服药记录
			</view>
		</view> -->
		<view class="view-item">
			<view class="tn-float-left left-view">
				<text class="color-title">服药时间</text>
			</view>
			<view class="tn-float-left right-view tn-text-right" >
				<text>{{detailInfo.medicationTime}}</text>
			</view>
		</view>
		<view class="view-item">
			<view class="tn-float-left tn-padding-right left-view">
				<text class="color-title">药品名称</text>
			</view>
			<view class="tn-float-left right-view tn-text-right">
				<text >{{detailInfo.name}}</text>
			</view>
		</view>
		<view class="view-item shuoming-item">
			<view class="tn-float-left tn-padding-right left-view shuoming-title">
				<text class="color-title">服药说明</text>
			</view>
			<view class="shuoming-str">
				<text class="tn-padding-right">{{detailInfo.explain}}</text>
			</view>
			<view class="tn-clear-float"></view>
		</view>
		<view class="view-item">
			<view class="tn-float-left tn-padding-right">
				<text class="tn-padding-right-sm color-title">药品图片</text>
			</view>
			<view class="img-content">
				<view class="img-up-view">
				  <view class="imgs-content-view">
					  <view v-for="(item,index) in fileImgList" :key="index" class="tn-image-upload__item">
						<image class="tn-image-upload__item__image" :src="item" mode="aspectFill" @click="showImage(item)"></image>
					  </view>
				  </view>
				</view>
			</view>
		</view>
		<view class="view-item">
			<view class="tn-float-left tn-padding-right">
				<text class="tn-padding-right-sm color-title">家长签名</text>
			</view>
			<view class="img-content">
				<view class="qianming-img">
					  <image v-if="detailInfo.autographImg" :src="detailInfo.autographImg" @click="showImage(detailInfo.autographImg, true)"></image>
					  <text v-else>无签名</text>
				</view>
			</view>
		</view>
		
		<view class="tn-padding-sm bottom-view" v-if="detailInfo.state == 0">
			<tn-button  width="45%" backgroundColor="#79CF67" fontColor="#ffffff" @click="editFunction">修改</tn-button>
			<tn-button class="right-btn" width="45%" backgroundColor="#E83A30" fontColor="#ffffff" @click="chexiaoFunction">撤销</tn-button>
		</view>
		<view v-if="previewImg" class="image-check-view tn-flex tn-flex-col-center" :class="isSign?'active':''" @click="previewImg=''">
			<image class="tn-width-full" :src="previewImg" mode="widthFix"></image>
			<text class="tn-icon-close" @click="previewImg=''"></text>
		</view>
		<tn-modal v-model="showmodal" :title="modaltitle" :content="modalcontent" :button="modalbutton" @click="modalClick"></tn-modal>
		<tn-toast
		  ref="toast"
		></tn-toast>
	</view>
</template>

<script>
	
	export default {
		name: 'youerruyuan',
		data(){
			return {
				fuyaoshijian: '',
				yaopinmingcheng: '',
				fuyaoshuoming: '',
				fileList: [],
				qianmingsrc: '',
				detailId: '',
				detailInfo: {},
				imageTitle: '',
				previewImg: '',
				fileImgList: [],
				isSign: false,
				modaltitle: '操作提醒',
				modalcontent: '撤销后将会彻底删除，确认撤销吗？',
				showmodal: false,
				modalbutton: [{
					text: '取消',
					backgroundColor: '#E6E6E6',
					fontColor: '#333333',
					plain: true,
					shape: 'round'
				  },
				  {
					text: '确定',
					backgroundColor: 'tn-bg-indigo',
					fontColor: '#FFFFFF'
				  }
				]
			}
		},
		onLoad:function(options){
		    console.log(options.id);   // 2
			this.detailId = options.id
		},
		onShow() {
			this.imageTitle = this.config.apiUri + '/sysFileInfo/previewImg?id=';
			this.getDetail()
		},
		mounted() {
			this.imageTitle = this.config.apiUri + '/sysFileInfo/previewImg?id=';
		},
		methods:{
			getDetail(){
				if(!this.detailId){
					return
				}
				this.request({
					url: '/MRegister/Get',
					method: 'get',
					params: {
						id: this.detailId
					},
				}).then(res => {
					if(res.code == 200){
						this.fileImgList = []
						this.detailInfo = res.data
						if(res.data.drugsImage){
							res.data.drugsImage.forEach(item => {
								this.fileImgList.push(this.imageTitle + item.filedId)
							})
						}
						
					}
				})
			},
			editFunction(){
				uni.navigateTo({
					url: `/pagesA/fuyao/dengji?id=${this.detailId}`
				})	
			},
			modalClick(val){
				console.log(val.index)
				if(val.index == 0){
					this.showmodal = false
				}else{
					
					let obj = [{
						id: this.detailId,
					}]
					this.request({
						url: '/MRegister/Delete',
						method: 'post',
						params: obj
					}).then(res => {
						if(res.code == 200){
							this.$refs.toast.show({
								title: '',
								content: res.message,
								icon: 'success',
								image: '',
								duration: 1500
							})
							uni.navigateBack({delta:1});
						}else{
							this.$refs.toast.show({
								title: '',
								content: res.message,
								icon: 'fail',
								image: '',
								duration: 1500
							})
						}
					})
				}
			},
			chexiaoFunction(){
				this.showmodal = true
			},
			showImage(item, issign){
				this.previewImg = item;
				this.isSign = issign?true:false
			},
		}
	}
</script>

<style lang="scss" scoped>
	.fuyao-body{
		min-height: 100vh;
		padding-bottom: 100rpx;
		background-color: rgba(245, 245, 245, 1);
	}
	.view1{
		overflow: hidden;
	}
	.avatar-item{
		height: 80rpx;
		line-height: 80rpx;
	}
	.names-view{
		margin-left: 20rpx;
		line-height: 80rpx;
	}
	.view-item{
		min-height: 80rpx;
		line-height: 80rpx;
		background-color: #ffffff;
		border-radius: 16rpx;
		padding:0 30rpx;
		margin-bottom: 16rpx;
	}
	.mingc-inp{
		width: 100%;
		margin-top: 18rpx;
		background-color: #ffffff;
	}
	.right-view{
		width: calc(100% - 150rpx);
		color: #555555;
	}
	.shuoming-title{
		line-height: 80rpx;
	}
	.left-view{
		width: 150rpx;
	}
	.img-up-view{
		margin-bottom: 30rpx;
	}
  .tn-image-upload__item {
    width: 100%;
    height: 180rpx;
    border-radius: 30rpx;
    margin-bottom: 20rpx;
		  float: left;
    &__image {
      width: 100%;
      height: 180rpx;
      border-radius: 30rpx;
    }
  }
  .tn-image-upload__custom-btn {
    background-color: $tn-font-holder-color;
    width: 100%;
    height: 180rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 30rpx;
  }
	.tn-image-upload__item {
	    width: 190rpx;
	    height: 190rpx;
	    border-radius: 30rpx;
	    margin-bottom: 20rpx;
		margin-right: 20rpx;
		position: relative;
	    &__image {
	      width: 100%;
	      height: 100%;
	      border-radius: 30rpx;
	    }
		  .tn-icon-close{
			  position: absolute;
			  top: 10rpx;
			  right: 10rpx;
			  font-size: 30rpx;
			  color: #333333;
			  line-height: 36rpx;
		  }
	  }
	  .image-check-view{
		  position: fixed;
		  top: 0;
		  left: 0;
		  right: 0;
		  bottom: 0;
		  z-index: 2;
		  background-color: rgba(1, 1, 1, 1);
		  &.active{
			  background-color: rgba(255,255,255, 1);
		  }
		  .tn-icon-close{
			  position: absolute;
			  top: 10rpx;
			  right: 10rpx;
			  font-size: 36rpx;
			  z-index: 888;
			  color: #333333;
			  line-height: 36rpx;
		  }
	  }
	  .imgs-content-view{
		  overflow: hidden;
	  }
	  .upload-view-cls{
		  width: 190rpx;
		  height: 190rpx;
		  border: 1px solid #dddddd;
		  float: left;
		  line-height: 190rpx;
		  text-align: center;
		  .tn-icon-add{
			  font-size: 80rpx;
		  }
	  }
	.img-content{
		overflow: hidden;
		width: 100%;
	}
	  .bottom-view{
		  position: fixed;
		  bottom: env(safe-area-inset-bottom);
		  left: 0rpx;
		  width: 100%;
		  z-index: 11;
		  background-color: rgba(245, 245, 245, 1);
	  }
	  .qianming-img{
		  width: 60%;
	  }
	  .shuoming-str{
		  width: calc(100% - 150rpx);
		  float: left;
		  color: #555555;
	  }
	  .shuoming-item{
		  
		  	min-height: 80rpx;
		  	line-height: 50rpx;
	  }
	  .right-btn{
		  margin-left: 8%;
	  }
	.color-title{
		font-weight: 550;
	}
</style>